package tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class FileUtil {
	public static void main(String[] args) throws Exception {
		System.out.println("a\034tt");
		search("/home/dsw/whitelog");
		analyze("/home/dsw/111122");
	}

	public static int analyze(String fileString) throws Exception {
		File file = new File(fileString);
		int count = 0;

		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis);
		BufferedReader br = new BufferedReader(isr);
		String adplansString = "";
		String admateString = "";

		String str = null;
		while (null != (str = br.readLine())) {
			if (str.matches("INFO  刷取广告位:adPlan id(.*)的条目不存在")) {
				System.out.println(str);
				String temString = str.substring(str.indexOf("id") + 2, str.indexOf("的"));
				System.out.println(temString);
				adplansString =adplansString + temString + ",";
			}
			if (str.matches("INFO  刷取广告位:material id(.*)的条目不存在")) {
				System.out.println(str);
				String temString = str.substring(str.indexOf("id") + 2, str.indexOf("的"));
				System.out.println(temString);
				admateString = admateString + temString + ",";
			}
		}
		System.out.println(count);
		
		System.out.println(adplansString);
		System.out.println(admateString);
		br.close();
		isr.close();
		fis.close();

		return count;
	}

	public static int search(String fileString) throws Exception {
		File file = new File(fileString);
		int count = 0;

		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis);
		BufferedReader br = new BufferedReader(isr);
		String str = null;
		while (null != (str = br.readLine())) {
			if (str.indexOf("发送成功") == -1) {
				str = str + br.readLine();
			}
			str = str.replace("^M", "");
			str = str.replace("<br>", "|");
			str = str.replace(" ", "");
			str = str.replace("目前有新购票信息，请确认", "");
			str = str.replace("目前有新购票信息，请确认", "");
			str = str.replace("目前有新购票信息，请确认", "");
			str = str.replace("|姓名:", "|");
			str = str.replace("|性别:", "|");
			str = str.replace("|所属地区:", "|");
			str = str.replace("|联系电话:", "|");
			str = str.replace("|公司名称:", "|");
			str = str.replace("|邮箱:", "|");
			str = str.replace("|部门:", "|");
			str = str.replace("|职位:", "|");
			str = str.replace("|发送成功", "|");

			System.out.println(str.substring(1) + "");
			count++;
			/*
			 * if(str.indexOf("male")==-1){ System.out.println(str); }
			 */
		}
		System.out.println(count);
		br.close();
		isr.close();
		fis.close();

		return count;
	}
}
